// collection---------------------------------------------------------------------
var dataArr = [];
var data1 = {
	"contentId" : "10014000400000002016080142748700",
	"contentName" : encodeURIComponent("三人行"),
	"contentPoster" : encodeURIComponent("/content/201609/10/20160910195315162.jpg"),
	"contentType" : "vod",
	"path" : "",
	"userId" : "test_chances",
	"category" : "category_21670026"
};
var data2 = {
	"contentId" : "02000006000000012016081999650011",
	"contentName" : encodeURIComponent("新口袋怪兽"),
	"contentPoster" : encodeURIComponent("/content/201609/11/20160911132315148.jpg"),
	"contentType" : "vod",
	"path" : "",
	"userId" : "test_chances",
	"category" : "category_21670026"
};
dataArr.push(data1);
dataArr.push(data2);

var program1 = "contentId=10014000400000002016080142748700&contentName="
		+ encodeURIComponent("三人行")
		+ "&contentPoster="
		+ encodeURIComponent("/content/201609/10/20160910195315162.jpg")
		+ "&contentType=vod&path=&userId=test_chances&category=category_21670026";

var program2 = "contentId=02000006000000012016081999650011&contentName="
		+ encodeURIComponent("新口袋怪兽")
		+ "&contentPoster="
		+ encodeURIComponent("/content/201609/11/20160911132315148.jpg")
		+ "&contentType=vod&path=&userId=test_chances&category=category_21670026"

function addCollection() {
	var url = "http://127.0.0.1/epg/user/fav/vod/add?";
	var reqParams = program2;
	ajaxCall(url + reqParams);
}

function removeCollection() {
	var url = "http://127.0.0.1/epg/user/fav/vod/remove?";
	var reqParams = "contentId=10014000400000002016080142748700&userId=test_chances";
	ajaxCall(url + reqParams);
}

function queryCollection() {
	var url = "http://127.0.0.1/epg/user/fav/vod/query?";
	var reqParams = "contentId=10014000400000002016080142748700&userId=test_chances";
	ajaxCall(url + reqParams);
}

function listCollection() {
	var url = "http://127.0.0.1/epg/user/fav/vod/list?";
	var reqParams = "userId=test_chances";
	ajaxCall(url + reqParams);
}

function clearCollections() {
	var url = "http://127.0.0.1/epg/user/fav/vod/clear?";
	var reqParams = "userId=test_chances";
	ajaxCall(url + reqParams);
}

function removeCollections() {
	var url = "http://127.0.0.1/epg/user/fav/vod/removeCollections";
	$.ajax({
				type : "POST",
				url : url,
				dataType : "json",
				contentType : "application/json",
				data : JSON.stringify(dataArr),
				success : function(data) {
					console.log(data);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					console.log(errorThrown);
				}
			});
}

function ajaxCall(_url) {
	$.ajax({
				method : 'get',
				url : _url,
				context : this,
				async : false,
				dataType : "json",
				success : function(data) {
					console.log(data);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					console.log(XMLHttpRequest);
					console.log(textStatus);
					console.log(errorThrown);
				}
			});
}

// subscription------------------------------------------------------------------
var scheduleParam1 = "userId=test_chances&code=02000001000000050000000000000003&type=schedule&title="
		+ encodeURIComponent("重播 十分好球(中超版)(0928)")
		+ "&prog=02000006000000052016052099000002&stbNo=EC2108B"
		+ "&nextDate="
		+ encodeURIComponent("2017-01-22 13:27:08")
		+ "&endDate="
		+ encodeURIComponent("2017-01-22 15:27:08");
var scheduleParam2 = "userId=test_chances&code=02000001000000050000000000000004	&type=schedule&title="
		+ encodeURIComponent("重播 篮球大本营(2016027)")
		+ "&prog=02000006000000052016052099200002&stbNo=EC2108B"
		+ "&nextDate="
		+ encodeURIComponent("2017-01-22 13:27:08")
		+ "&endDate="
		+ encodeURIComponent("2017-01-22 15:27:08");
function addUserSubscription() {
	var url = "http://127.0.0.1/epg/user/subscr/add?";
	var reqParams = scheduleParam2;
	ajaxCall(url + reqParams);
}

function removeUserSubscription() {
	var url = "http://127.0.0.1/epg/user/subscr/remove?";
	var reqParams = "userId=test_chances&code=02000001000000050000000000000003";
	ajaxCall(url + reqParams);
}

function listeUserSubscription() {
	var url = "http://127.0.0.1/epg/user/subscr/list?";
	var reqParams = "userId=test_chances&stbNo=EC2108B";
	ajaxCall(url + reqParams);
}

function delSubscrs() {
	var url = "http://127.0.0.1/epg/user/subscr/delSubscrs?";
	var reqParams = "userId=test_chances&stbNo=EC2108B&codes=02000001000000050000000000000003,"
			+ "02000001000000050000000000000004";
	ajaxCall(url + reqParams);
}

// test-------------------------------------------------------------------------
// addCollection();
// removeCollection();
// queryCollection();
// listCollection();
// clearCollections();
// removeCollections();
// addUserSubscription();
// removeUserSubscription();
// listeUserSubscription();
delSubscrs();
